//hud crosshair
// ---- Created with geo-11 v0.7.7 on Fri Oct 23 00:56:47 2026



// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);
Texture2D<float> DepthBuffer : register(t110);

static const float near = 0.0001;
static const float far = 1;

float world_z_from_depth_buffer(float x, float y)
{
    uint width, height;
    float z;

    DepthBuffer.GetDimensions(width, height);

    x = min(max((x / 2 + 0.5) * width, 0), width - 1);
    y = min(max((-y / 2 + 0.5) * height, 0), height - 1);
    z = DepthBuffer.Load(int3(x, y, 0)).x;
    if (z == 1)
        return 0;

    //return (far*near/((z)*near) + (far*z));
	return (far*near/((1-z)*near) + (far*z));
}

float adjust_from_depth_buffer(float x, float y)
{
    float4 stereo = StereoParams.Load(0);
	float4 testeo = IniParams.Load(int2(90,0));
    if (stereo.x==0) {return 0;}
    
    float separation = stereo.x; 
    float convergence = stereo.y;
    float old_offset, offset, w, sampled_w, distance;
    uint i;

    offset = (near - convergence) * separation ;
    distance = separation - offset;

    old_offset = offset;
    
    for (i = 0; i < 255; i++) {
        offset += distance / 255.0;
        w = (separation * convergence*10) / (separation - offset);
        sampled_w = world_z_from_depth_buffer(x + offset, y);
        
        if (sampled_w == 0)
            return separation;

        if (w > sampled_w)
            break;

        old_offset = offset;
    }

    return old_offset;
}


void main(
  float2 v0 : Texcoords0,
  float4 v1 : Colour0,
  float4 v2 : SV_Position0,
  out float2 o0 : Texcoords0,
  out float4 o1 : Colour0,
  out float4 o2 : SV_Position0)
{
	
float4 s = StereoParams.Load(0);  
float4 testeo = IniParams.Load(int2(90,0));	
float cursor_showing = IniParams[1].z; 

	
  o0.xy = v0.xy;
  o1.xyzw = v1.xyzw;
  o2.xyzw = v2.xyzw;

if (!cursor_showing) {
	if (abs(o2.x) < 0.5 && abs(o2.y) < 0.36) {	
      o2.x += adjust_from_depth_buffer(0, 0);
    } else {
        o2.x += s.x * 0.25;
    }
}
//o2.x += s.x * testeo.x;  
  
  return;
}





/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
//   using 3Dmigoto v0.7.7 on Fri Oct 23 00:56:47 2026
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// Texcoords                0   xy          0     NONE   float   xy
// Colour                   0   xyzw        1     NONE   float   xyzw
// SV_Position              0   xyzw        2     NONE   float   xyzw
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// Texcoords                0   xy          0     NONE   float   xy
// Colour                   0   xyzw        1     NONE   float   xyzw
// SV_Position              0   xyzw        2      POS   float   xyzw
//
vs_4_0
dcl_input v0.xy
dcl_input v1.xyzw
dcl_input v2.xyzw
dcl_output o0.xy
dcl_output o1.xyzw
dcl_output_siv o2.xyzw, position
mov o0.xy, v0.xyxx
mov o1.xyzw, v1.xyzw
mov o2.xyzw, v2.xyzw
ret
// Approximately 4 instruction slots used

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
